import axios from 'axios';

const service = axios.create({
  baseURL: '',
  timeout: 3000e1,
});
service.interceptors.request.use(
  (config) => {
    config.headers = {
      v: window.API_VERSION || '115',
    };
    return config;
  },
  (error) => Promise.reject(error),
);

// 响应拦截器
service.interceptors.response.use(
  (res) => {
    const requestCode = res.data.code;
    if (requestCode === 0) {
      return Promise.resolve(res.data);
    }
    return Promise.resolve(res.data);
  },
  (error) => Promise.reject(error),
);

export default service;
